﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.Objects;
using System.Data.Objects.DataClasses;
using Negocio;

namespace View
{
    public partial class PlanoAulaList : Form
    {
        public PlanoAulaList()
        {
            InitializeComponent();
        }

        private void PlanoAulaList_Load(object sender, EventArgs e)
        {
            //Initialize the ObjectContext
            using (BancoDadosEntities schoolContext = new BancoDadosEntities())
            {
                var resultado = from u in schoolContext.Universidade
                                    .Include(schoolContext.Curso.EntitySet.Name)
                                orderby u.Nome
                                select u;

                this.ddlUniversidade.DisplayMember = "Nome";
                this.ddlUniversidade.DataSource = ((ObjectQuery)resultado).Execute(MergeOption.AppendOnly);
            }
        }

        private void ddlUniversidade_SelectedIndexChanged(object sender, EventArgs e)
        {
            Universidade Universidade = (Universidade)this.ddlUniversidade.SelectedItem;
            ddlCurso.DataSource = Universidade.Curso;
            ddlCurso.DisplayMember = "Nome";
        }

        private void ddlCurso_SelectedIndexChanged(object sender, EventArgs e)
        {
            grid.DataSource = null;
            Curso curso = (Curso)this.ddlCurso.SelectedItem;
            using (BancoDadosEntities bd = new BancoDadosEntities())
            {
                ddlMateria.DataSource = bd.Materia.Include(bd.PlanoAula.EntitySet.Name).Where(s => s.IdCurso == curso.Id);
                ddlMateria.DisplayMember = "Nome";
            }
        }
        private void ddlMateria_SelectedIndexChanged(object sender, EventArgs e)
        {
            Materia materia = this.ddlMateria.SelectedItem as Materia;
            Guid id = Guid.NewGuid();
            if (materia != null)
            {
                id = materia.Id;
            }
            using (BancoDadosEntities bd = new BancoDadosEntities())
            {
                grid.AutoGenerateColumns = false;
                grid.DataSource = from plano in bd.PlanoAula
                                  where plano.IdMateria == materia.Id
                                  select plano;
            }
        }

    }
}
